import Vue from 'vue'
import Router from 'vue-router'
import {
    Notification
} from 'element-ui'
Vue.prototype.$notify = Notification;
Vue.use(Router)

//题库管理
import questionMange from '@/pages/question_bank/index'

//订单管理
import orderMange from '@/pages/orderMange/index'

//团体报名
import groupRegistration from '@/pages/groupRegistration/index'
import signUp from '@/pages/groupRegistration/signUp'
import matchList from '@/pages/groupRegistration/matchList'
import matchDetail from '@/pages/groupRegistration/matchDetail'
import group from '@/pages/groupRegistration/group'
import signList from '@/pages/groupRegistration/signList'

// 直播展示
import liveDisplay from '@/pages/live/index'
import liveMoreDisplay from '@/pages/live/multiScreen'
import everyGroundLed from '@/pages/live/every_ground_led'
import Score from '@/pages/live/score'
import Led from '@/pages/live/led'
import LedFour from '@/pages/live/led_four'
//登录页路由
import Login from '@/pages/login/index'
//系统主页面路由
import Index from '@/components/index'
//系统主页面下子路由
// import Home from '@/pages/home/index'

/**********************************用户管理*************************************/
import User from '@/pages/user/index'
import organizationList from '@/pages/user/organizationList'
import organizationInfo from '@/pages/user/organizationInfo'
import organizationCheck from '@/pages/user/organizationCheck'
import organizationCheckMatch from '@/pages/user/organizationCheckMatch'
import umpireList from '@/pages/user/umpireList'
import umpireListInfo from '@/pages/user/umpireListInfo'
import umpireListCheck from '@/pages/user/umpireListCheck'
import umpireCheckMatch from '@/pages/user/umpireCheckMatch'
import organizationMatchDetails from '@/pages/user/organizationMatchDetails'
import umpireMatchDetails from '@/pages/user/umpireMatchDetails'

/**********************************用户管理 - 运动员列表**********************/
import playerIndex from '@/pages/user/playerList/index'
import playerList from '@/pages/user/playerList/playerList'

/**********************************权限管理*************************************/
import power from '@/pages/power/index'
import powerManage from '@/pages/power/powerManage'
import powerKeyword from '@/pages/power/keyword'
import logList from '@/pages/power/logList'
/**********************************赛事管理*************************************/
import Match from '@/pages/match/index'
//查看战绩
import ScoreAll from '@/pages/Match/Score/all'
import ScoreLoop from '@/pages/Match/Score/loop'
import ScoreKnock from '@/pages/Match/Score/knock'
//排战表
import Schedule from '@/pages/Match/Schedule/schedule'
import ScheduleHandle from '@/pages/Match/Schedule/scheduleHandle'
import CheckSchedule from '@/pages/Match/Schedule/checkSchedule'
//检查&发布
import CheckKnock from '@/pages/Match/Check/checkKnock'
import CheckLoop from '@/pages/Match/Check/checkLoop'
import ReleaseKnock from '@/pages/Match/Check/releaseKnock'
import ReleaseLoop from '@/pages/Match/Check/releaseLoop'

//裁判评估
import refereeEvaluation from '@/pages/match/RefereeEvaluation/RefereeEvaluation'

//编排
import Layout from '@/pages/Match/Layout/layout'
import LayoutDraw from '@/pages/match/Layout/LayoutDraw'
import LayoutHandDraw from '@/pages/Match/Layout/LayoutHandDraw'
import LayoutResult from '@/pages/Match/Layout/layoutResult'
/*****************************************************************************/
// import Question from '@/pages/question/index'

import Permission from '@/pages/permission/index'

//match下子路由
import AddNewMatch from '@/pages/match/AddNewMatch'
import MatchHome from '@/pages/match/MatchHome'
import AddMatchDetail from '@/pages/match/ListManageReferee/AddMatchDetail'
//查看赛事
import MatchSignUp from '@/pages/match/ListManageSignUp/MatchSignUp'
import MatchDetail from '@/pages/match/ListManageSignUp/MatchDetail'
import CheckMatchSignUp from '@/pages/match/ListManageSignUp/checkMatchSignUp'
import checkLive from '@/pages/match/ListManageSignUp/live'
import MatchRules from '@/pages/match/MatchRules/rules'
// 404
import error_404 from '@/pages/error-page/404'

const router = new Router({
    routes: [{
        path: '/',
        redirect: 'Index'
    },
    {
        path: '/Index',
        component: Index,
        children: [{
            path: '',
            redirect: 'Match'
        },
        {
            path: 'power',
            component: power,
            children: [{
                path: 'powerManage',
                component: powerManage,
            },
            {
                path: 'keyword',
                component: powerKeyword,
            },
            {
                path: 'logList',
                component: logList,
            },
            {
                path: 'matchLog',
                component: ()=>import("../pages/power/matchLog"),
            },
            ]
        },
        {
            path: 'User',
            component: User,
            children: [
                //裁判列表
                {
                    path: 'umpireList',
                    component: umpireList,
                },
                {
                    path: 'organizationList',
                    component: organizationList,
                },
                {
                    path: 'organizationInfo',
                    component: organizationInfo,
                },
                {
                    path: 'organizationCheck',
                    component: organizationCheck,
                },
                {
                    path: 'umpireListInfo',
                    component: umpireListInfo,
                },
                {
                    path: 'umpireListCheck',
                    component: umpireListCheck,
                },
                {
                    path: 'organizationCheckMatch',
                    component: organizationCheckMatch,
                },
                {
                    path: 'umpireCheckMatch',
                    component: umpireCheckMatch,
                },
                {
                    path: 'organizationMatchDetails',
                    component: organizationMatchDetails,
                },
                {
                    path: 'umpireMatchDetails',
                    component: umpireMatchDetails,
                },
                {
                    path: 'playerList',
                    component: playerList,
                },
                {
                    path: 'playerIndex',
                    component: playerIndex,
                }
            ]
        },
        {
            path: 'orderMange',
            component: orderMange,
        },
        {
            path: 'questionMange',
            component: questionMange,
            children: [{
                name: 'knowledge_spot',
                path: 'knowledge_spot',
                component: () =>
                    import('@/pages/question_bank/knowledge_spot'),
            },
            {
                name: 'test_questions',
                path: 'test_questions',
                component: () =>
                    import('@/pages/question_bank/test_questions'),
            },
            {
                name: 'tennisRule',
                path: 'tennisRule',
                component: () =>
                    import('@/pages/question_bank/tennis_rule'),
            },
            {
                name: 'knowledge_edit',
                path: 'knowledge_edit',
                component: () =>
                    import('@/pages/question_bank/knowledge_edit'),
            },
            {
                name: 'add_questions',
                path: 'add_questions',
                component: () =>
                    import('@/pages/question_bank/add_questions'),
            }
            ]
        },
        //团体报名
        {
            path: 'groupRegistration',
            component: groupRegistration,

        },
        {
            path: 'signUp',
            component: signUp,

        },

        {
            path: 'matchList',
            component: matchList
        },
        {
            path: 'matchDetail',
            component: matchDetail
        },
        {
            path: 'group/:id',
            component: group
        },
        {
            path: 'signList',
            component: signList
        },


        {
            path: 'Permission',
            component: Permission
        },
        // {
        //   path: 'Question',
        //   component: Question
        // },
        {
            path: 'Match',
            component: Match,
            children: [{
                path: '',
                component: MatchHome,
            },
            //添加新赛事
            {
                path: 'AddNewMatch',
                component: AddNewMatch
            },
            //添加赛事详情
            {
                path: 'AddMatchDetail',
                component: AddMatchDetail,
            },
            //查看赛事
            {
                path: 'MatchDetail',
                component: MatchDetail,
            },
            {
                path: 'MatchSignUp',
                component: MatchSignUp,
            },
            {
                path: 'MatchRules',
                component: MatchRules,
            },
            {
                path: 'CheckMatchSignUp',
                component: CheckMatchSignUp,
            },
            {
                path: 'live',
                component: checkLive,
            },
            {
                path: 'scoreList',
                component: ScoreAll
            },
            {
                path: 'scoreList',
                component: ScoreAll
            },
            {
                path: 'scoreknock',
                component: ScoreKnock
            },
            {
                path: 'schedule',
                component: Schedule
            },
            {
                path: 'scheduleHandle',
                component: ScheduleHandle
            },
            {
                path: 'checkSchedule',
                component: CheckSchedule
            },
            {
                path: 'refereeEvaluation',
                component: refereeEvaluation
            },
            //发布检查
            {
                path: 'checkLoop',
                component: CheckLoop
            },
            {
                path: 'checkKnock',
                component: CheckKnock
            },
            {
                path: 'releaseLoop',
                component: ReleaseLoop
            },
            {
                path: 'releaseKnock',
                component: ReleaseKnock
            },
            //编排
            {
                path: 'layout',
                component: Layout,
            },
            {
                path: 'LayoutDraw',
                component: LayoutDraw,
            },
            {
                path: 'LayoutHandDraw',
                component: LayoutHandDraw,
            },
            {
                path: 'LayoutResult',
                component: LayoutResult,
            }
            ],
        },

        ]
    },
    {
        path: '/Login',
        component: Login
    },
    {
        path: '/liveDisplay',
        component: liveDisplay,
    },
    {
        path: '/liveMoreDisplay',
        component: liveMoreDisplay,
    },
    {
        path: '/everyGroundLed',
        component: everyGroundLed,
    },
    {
        path: '/score',
        component: Score,
    },
    {
        path: '/led',
        component: Led,
    },
    {
        path: '/led_four',
        component: LedFour,
    },
    {
        path: '*',
        component: error_404,
    },
    ],
    scrollBehavior(to, from, savedPosition) {
        return {
            x: 0,
            y: 0
        }
    }
})
//全局路由守卫
router.beforeEach((to, from, next) => {
    let isLogin = window.sessionStorage.getItem('token'); // 是否登录
    if (!isLogin && to.path != '/Login' && to.path != '/led_four' && to.path != '/liveDisplay' && to.path != '/led' && to.path != '/liveMoreDisplay' && to.path != '/everyGroundLed' && to.path != '/score') {
        next({
            path: '/Login'
        })
    } else {
        let user_type = window.sessionStorage.getItem('user_type')
        if (to.path == '/index/match/schedule' || to.path == '/index/match/scheduleHandle' || to.path ==
            '/index/match/checkSchedule') {
            if (user_type == 2 || user_type == 0) {
                Vue.prototype.$notify({
                    title: '权限不足',
                    message: '只有裁判才能进入编排',
                    type: 'warning'
                });
                if (from.fullPath) {
                    next({
                        path: '/index/match'
                    })
                } else {
                    next({
                        path: from.fullPath
                    })
                }
            } else next()
        }
        next();
    }
});
//导航
export default router
